From 80af1058c0b9f6a8ab14d574b2b04e3752151abe Mon Sep 17 00:00:00 2001 From: tsteven4 <13596209+tsteven4@users.noreply.github.com> Date: Sun, 9 Jun 2019 17:14:36 -0600 Subject: [PATCH] remove dependency on glob. (#367) * remove dependency on glob. and have magproto invoke the rd_deinit function when it uses the gpx reader (uggh). * regenerate configure on linux. --- CMakeLists.txt | 2 +- GPSBabel.pro | 2 +- config.h.in | 3 --- configure | 9 ++++---- configure.ac | 2 +- magproto.cc | 63 +++++++++++++++++++++----------------------------- 6 files changed, 33 insertions(+), 48 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 0a2f1bdad..0ba561b14 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -188,7 +188,7 @@ if(UNIX) if(${HAVE_STDARG_H}) add_definitions(-DHAVE_STDARG_H) endif() - add_definitions(-DHAVE_LIBUSB -DHAVE_GLOB) + add_definitions(-DHAVE_LIBUSB) set(SOURCES ${SOURCES} gbser_posix.cc) set(HEADERS ${HEADERS} gbser_posix.h) set(JEEPS ${JEEPS} jeeps/gpslibusb.cc) diff --git a/GPSBabel.pro b/GPSBabel.pro index 87c63c32c..0749981fc 100644 --- a/GPSBabel.pro +++ b/GPSBabel.pro @@ -175,7 +175,7 @@ macx|linux { # this is used by zlib DEFINES += HAVE_STDARG_H } - DEFINES += HAVE_LIBUSB HAVE_GLOB + DEFINES += HAVE_LIBUSB SOURCES += gbser_posix.cc HEADERS += gbser_posix.h JEEPS += jeeps/gpslibusb.cc diff --git a/config.h.in b/config.h.in index 70f190ccc..4a39b83a4 100644 --- a/config.h.in +++ b/config.h.in @@ -12,9 +12,6 @@ /* define if the compiler supports basic C++14 syntax */ #undef HAVE_CXX14 -/* Define to 1 if you have the `glob' function. */ -#undef HAVE_GLOB - /* Define to 1 if you have the header file. */ #undef HAVE_INTTYPES_H diff --git a/configure b/configure index b0934ae45..2181cae1d 100755 --- a/configure +++ b/configure @@ -6673,13 +6673,12 @@ done # AC_FUNC_STRTOD # AC_FUNC_VPRINTF # AC_CHECK_FUNCS([atexit floor localtime_r memmove memset pow select sqrt strchr strcspn strdup strerror strncasecmp strrchr strspn strstr strtol strtoul]) -for ac_func in uname glob +for ac_func in uname do : - as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh` -ac_fn_cxx_check_func "$LINENO" "$ac_func" "$as_ac_var" -if eval test \"x\$"$as_ac_var"\" = x"yes"; then : + ac_fn_cxx_check_func "$LINENO" "uname" "ac_cv_func_uname" +if test "x$ac_cv_func_uname" = xyes; then : cat >>confdefs.h <<_ACEOF -#define `$as_echo "HAVE_$ac_func" | $as_tr_cpp` 1 +#define HAVE_UNAME 1 _ACEOF fi diff --git a/configure.ac b/configure.ac index ceaefd378..9cd94327b 100644 --- a/configure.ac +++ b/configure.ac @@ -410,7 +410,7 @@ AC_CHECK_HEADERS([unistd.h stdarg.h]) # AC_FUNC_STRTOD # AC_FUNC_VPRINTF # AC_CHECK_FUNCS([atexit floor localtime_r memmove memset pow select sqrt strchr strcspn strdup strerror strncasecmp strrchr strspn strstr strtol strtoul]) -AC_CHECK_FUNCS([uname glob]) +AC_CHECK_FUNCS([uname]) # # There's probably some more "autoconfish" way to do this. diff --git a/magproto.cc b/magproto.cc index 0b9da8b00..ab3ed6e91 100644 --- a/magproto.cc +++ b/magproto.cc @@ -20,8 +20,6 @@ */ -#include "defs.h" // might include config.h, which might define HAVE_GLOB. - #include // for isprint, toupper #include // for fabs, lround #include // for sprintf, sscanf, snprintf, size_t @@ -29,20 +27,20 @@ #include // for strchr, strncmp, strlen, memmove, strrchr, memset #include // for gmtime -#if HAVE_GLOB -#include -#endif - #include // for QByteArray #include // for QCharRef +#include // for QDir, operator|, QDir::Files, QDir::Name, QDir::Readable #include // for QFileInfo +#include // for QFileInfoList #include // for QLatin1String #include // for QList #include // for QString, operator== +#include // for QStringList #include // for QTime #include // for CaseInsensitive #include // for qPrintable, foreach +#include "defs.h" #include "explorist_ini.h" // for explorist_ini_done, explorist_ini_get, mag_info #include "gbfile.h" // for gbfclose, gbfeof, gbfgets, gbfopen, gbfwrite, gbfile #include "gbser.h" // for gbser_deinit, gbser_init, gbser_is_serial, gbser_read_line, gbser_set_port, gbser_write, gbser_OK @@ -80,7 +78,7 @@ static int extension_hint; // (This has nothing to do with the Explorist 100...600 products.) static ff_vecs_t* gpx_vec; static mag_info* explorist_info; -static char** os_gpx_files(const char* dirname); +static QStringList os_gpx_files(const char* dirname); /* * Magellan's firmware is *horribly* slow to send the next packet after @@ -268,7 +266,7 @@ m330_cleanse(const char* istring) "abcdefghijklmnopqrstuvwxyz" "0123456789+-.'/!@#<%^&>()=:\\"; char* rstring = (char*) xmalloc(strlen(istring)+1); - char* o; + char* o; const char* i; for (o=rstring,i=istring; *i; i++) { @@ -540,7 +538,7 @@ retry: if (idx > 0) { s.truncate(idx); } - + trk_head->rte_name = s; track_add_head(trk_head); } @@ -1249,25 +1247,25 @@ static void mag_read() { if (gpx_vec) { - char** f = os_gpx_files(explorist_info->track_path); - while (f && *f) { - gpx_vec->rd_init(*f); + QStringList f = os_gpx_files(explorist_info->track_path); + for (const auto& file : qAsConst(f)) { + gpx_vec->rd_init(file); gpx_vec->read(); - f++; + gpx_vec->rd_deinit(); } f = os_gpx_files(explorist_info->waypoint_path); - while (f && *f) { - gpx_vec->rd_init(*f); + for (const auto& file : qAsConst(f)) { + gpx_vec->rd_init(file); gpx_vec->read(); - f++; + gpx_vec->rd_deinit(); } #if 0 f = os_gpx_files(explorist_info->geo_path); - while (f && *f) { - gpx_vec->rd_init(*f); + for (const auto& file : qAsConst(f)) { + gpx_vec->rd_init(file); gpx_vec->read(); - f++; + gpx_vec->rd_deinit(); } #endif return; @@ -1582,27 +1580,18 @@ const char** os_get_magellan_mountpoints() #endif } -// My kingdom for container classes and portable tree-walking... -// Returns a pointer to a static vector that's valid until the next call. -#if HAVE_GLOB -static char** +static QStringList os_gpx_files(const char* dirname) { - static glob_t g; - char* path; - xasprintf(&path, "%s/*.gpx", dirname); - glob(path, 0, nullptr, &g); - xfree(path); - return g.gl_pathv; -} -#else -static char** -os_gpx_files(const char* /* dirname */) -{ - fatal("Not implemented"); - return NULL; + QDir dir(dirname); + + const QFileInfoList filist = dir.entryInfoList(QStringList("*.gpx"), QDir::Files | QDir::Readable, QDir::Name); + QStringList rv; + for (const auto& fi : filist) { + rv.append(fi.absoluteFilePath()); + } + return rv; } -#endif /* * This is repeated just so it shows up as separate menu options -- 2.30.2